Public Class verDesgloseGrupal

    Private idE As Integer
    Private idG As Integer
    Private nombre As String
    Private activo As Integer
    Private promedios As ArrayList
    Dim datos As DataTable
    Private gestor As capaNegocios.Gestor = gestor.instanciar

    Public Sub cargarDatos(ByVal pidE As Integer, ByVal pidG As Integer, ByVal pnombre As String, ByVal pactivo As Integer)
        Me.idE = pidE
        Me.idG = pidG
        Me.nombre = pnombre
        Me.activo = pactivo
    End Sub

    Private Sub cargarLista()
        With gestor
            Me.listaDesglose.Refresh()
            datos = .mostrarDesgloseEquipo(Me.idG, Me.idE)
            listaDesglose.DataSource = datos
        End With
        If datos.Rows.Count > 0 Then
            Me.TextNota.Enabled = True
        End If
    End Sub

    Private Sub cargarListaEstudiantes()

    End Sub

    Private Sub asignarNota(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextNota.KeyDown
        Dim fila As Integer
        Try
            If e.KeyCode = Keys.Enter Then
                If MessageBox.Show("Desea modificar la nota?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) = Windows.Forms.DialogResult.Yes Then
                    Dim nota As String = CType(Me.TextNota.Text, String)
                    fila = listaDesglose.CurrentRow.Index
                    Dim idR As Integer = CInt(listaDesglose(2, fila).Value)
                    gestor.modificarNotaGrupal(Me.idG, Me.idE, idR, nota)
                    Me.cargarLista()
                    Me.cargarCampos()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub mostrarNota(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listaDesglose.SelectionChanged
        If listaDesglose.CurrentRow IsNot Nothing Then
            Dim fila As Integer
            fila = listaDesglose.CurrentRow.Index
            'Dim nota As String = listaDesglose(1, fila).Value
            Me.TextNota.Text = CInt(listaDesglose(1, fila).Value) 'nota
        End If
    End Sub

    Private Sub cargarEstudiante(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listaDesglose.SelectionChanged
        Dim dtEst As DataTable
        Dim idR As Integer
        Dim msj As String
        If listaDesglose.CurrentRow IsNot Nothing Then
            Dim fila As Integer
            fila = listaDesglose.CurrentRow.Index
            idR = CInt(listaDesglose(2, fila).Value)
            dtEst = gestor.obtenerNotasEstudiantes(idG, idE, idR)
            Me.listaNotasEstudiantes.DataSource = dtEst
            msj = gestor.obtenerSumatoria(idG, idE, idR)
            Me.TextBox4.Text = msj
            If dtEst.Rows.Count > 0 Then
                Me.TextNotaEstudiante.Enabled = True
            Else
                Me.TextNotaEstudiante.Enabled = False
            End If
        End If
    End Sub

    Private Sub mostrarNotaEstudiante(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listaNotasEstudiantes.SelectionChanged
        If listaNotasEstudiantes.CurrentRow IsNot Nothing Then
            Dim fila As Integer
            fila = listaNotasEstudiantes.CurrentRow.Index
            'Dim nota As String = listaDesglose(1, fila).Value
            Me.TextNotaEstudiante.Text = CInt(listaNotasEstudiantes(0, fila).Value) 'nota
        End If
    End Sub

    Private Sub asignarNotaEstudiante(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextNotaEstudiante.KeyDown
        Dim fila, filaR, idEst, idR As Integer
        Try
            If e.KeyCode = Keys.Enter Then
                If MessageBox.Show("Desea modificar la nota?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) = Windows.Forms.DialogResult.Yes Then
                    Dim nota As String = CType(Me.TextNotaEstudiante.Text, String)
                    filaR = Me.listaDesglose.CurrentRow.Index
                    fila = listaNotasEstudiantes.CurrentRow.Index
                    idR = CInt(listaDesglose(2, filaR).Value)
                    idEst = CInt(Me.listaNotasEstudiantes(3, filaR).Value)
                    gestor.modificarNota(idG, idEst, idR, nota)
                    Me.cargarLista()
                    Me.cargarCampos()
                    Me.cargarListaEstudiantes()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub cargarCampos()
        Me.TextEstudiante.Text = nombre
        promedios = gestor.mostrarPromedioEquipo(Me.idG, Me.idE)
        Dim a, b, c As ArrayList
        a = promedios.Item(0)
        b = promedios.Item(1)
        c = promedios.Item(2)
        Me.TextBox1.Text = a.Item(0) & " %  / " & a.Item(1) & " % "
        Me.TextBox2.Text = b.Item(0) & " %  / " & b.Item(1) & " % "
        Me.TextBox3.Text = c.Item(0) & " %  / " & c.Item(1) & " % "
    End Sub

    Private Sub cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cerrar.Click
        Me.Close()
    End Sub

    Private Sub verDesgloseGrupal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cargarLista()
        Me.cargarCampos()
        If (Me.activo = 0) Then
            Me.TextNota.Visible = False
            Me.TextNotaEstudiante.Visible = False
        End If
    End Sub
End Class